HAL HASH initialization and configuration functions migration ¶
The goal of this page is to show how to migrate the initialization sequence using STM32CubeMX2:
Open STM32CubeMX2 HASH configuration panel.
Configure the SW layer HAL.
Configure the main HASH features.
Configure the HASH DMA(s) if the application requires the HASH to be used in DMA mode.
Configure the NVIC if the application requires the HASH to be used in IT mode.
Generate the code.
Note
The configuration below might vary from a series to another.
HAL HASH configuration panel ¶
Create a new project with the STM32CubeMX2, then start the initialization and the main configuration.
HAL HASH main features configuration ¶
Select the algorithm and data swapping and Configure the HMAC settings.
DMA configuration ¶
Configure the DMA for data reception as needed.
NVIC configuration ¶
Configure the NVIC in case of an interrupt.
Generated HASH initialization and de-initialization sequences ¶
The HASH initialization sequence is generated in the
mx_hash_init
and
mx_hash_deinit
functions in
mx_hash.c
file under
$YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.
Related concepts:
|
Topic |
Code Snippet HAL1 |
Code Snippet HAL2 |
|---|---|---|
|
Handle declaration |
HASH_HandleTypeDef hhash;
|
hal_hash_handle_t hHASH;
|
|
Init, config and Msp sequence function |
static void MX_HASH_Init(void)
{
hhash.Init.DataType = HASH_DATATYPE_8B;
hhash.Init.KeySize = 261;
hhash.Init.pKey = (uint8_t *)input_key;
if (HAL_HASH_Init(&hhash) != HAL_OK)
{
Error_Handler();
}
void HAL_HASH_MspInit(HASH_HandleTypeDef* hhash)
{
if(hhash->Instance==HASH)
{
/* Peripheral clock enable */
__HAL_RCC_HASH_CLK_ENABLE();
/* HASH interrupt Init */
HAL_NVIC_SetPriority(HASH_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(HASH_IRQn);
}
}
|
hal_hash_handle_t *mx_hash_init(void)
{
hal_hash_config_t config;
if (HAL_HASH_Init(&hHASH, HAL_HASH) != HAL_OK)
{
return NULL;
}
HAL_RCC_HASH_EnableClock();
config.data_swapping = HAL_HASH_DATA_SWAP_NO;
config.algorithm = HAL_HASH_ALGO_SHA1;
if (HAL_HASH_SetConfig(&hHASH, &config) != HAL_OK)
{
return NULL;
}
/* Enable the interruption for HASH */
HAL_CORTEX_NVIC_SetPriority(HASH_IRQn, HAL_CORTEX_NVIC_PREEMP_PRIORITY_0, HAL_CORTEX_NVIC_SUB_PRIORITY_0);
HAL_CORTEX_NVIC_EnableIRQ(HASH_IRQn);
return &hHASH;
}
|
|
Deinit sequence function |
void MX_HASH_DeInit(void)
{
if (HAL_HASH_DeInit(&hhash) != HAL_OK)
{
Error_Handler();
}
}
void HAL_HASH_MspDeInit(HASH_HandleTypeDef* hhash)
{
if(hhash->Instance==HASH)
{
/* Peripheral clock disable */
__HAL_RCC_HASH_CLK_DISABLE();
/* HASH interrupt DeInit */
HAL_NVIC_DisableIRQ(HASH_IRQn);
}
}
|
void mx_hash_deinit(void)
{
/* Disable the interruption for HASH */
HAL_CORTEX_NVIC_DisableIRQ(HASH_IRQn);
(void)HAL_HASH_DeInit(&hHASH);
HAL_RCC_HASH_Reset();
HAL_RCC_HASH_DisableClock();
}
|
|
HASH IRQ handler sequence |
void HASH_IRQHandler(void)
{
HAL_HASH_IRQHandler(&hhash);
}
|
void HASH_IRQHandler(void)
{
HAL_HASH_IRQHandler(&hHASH);
}
|